﻿/**  版本信息模板在安装目录下，可自行修改。
* zaixianmokao.cs
*
* 功 能： N/A
* 类 名： zaixianmokao
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2014/11/30 14:41:50   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace XinKuaiJi.DAL
{
	/// <summary>
	/// 数据访问类:zaixianmokao
	/// </summary>
	public partial class zaixianmokao
	{
		public zaixianmokao()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(long baocun_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from zaixianmokao");
			strSql.Append(" where baocun_id=@baocun_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@baocun_id", MySqlDbType.Int64,20)			};
			parameters[0].Value = baocun_id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(XinKuaiJi.Model.zaixianmokao model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into zaixianmokao(");
			strSql.Append("baocun_id,user_id,zuihoutime,dt_xuanze,dt_jisuan,dt_panduan,dt_anli,dt_caozuo,mk_id,k_id,shengyutime,baoliu1,baoliu2)");
			strSql.Append(" values (");
			strSql.Append("@baocun_id,@user_id,@zuihoutime,@dt_xuanze,@dt_jisuan,@dt_panduan,@dt_anli,@dt_caozuo,@mk_id,@k_id,@shengyutime,@baoliu1,@baoliu2)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@baocun_id", MySqlDbType.Int64,20),
					new MySqlParameter("@user_id", MySqlDbType.Int32,11),
					new MySqlParameter("@zuihoutime", MySqlDbType.DateTime),
					new MySqlParameter("@dt_xuanze", MySqlDbType.VarChar,500),
					new MySqlParameter("@dt_jisuan", MySqlDbType.VarChar,45),
					new MySqlParameter("@dt_panduan", MySqlDbType.VarChar,45),
					new MySqlParameter("@dt_anli", MySqlDbType.VarChar,45),
					new MySqlParameter("@dt_caozuo", MySqlDbType.VarChar,45),
					new MySqlParameter("@mk_id", MySqlDbType.VarChar,45),
					new MySqlParameter("@k_id", MySqlDbType.Int32,11),
					new MySqlParameter("@shengyutime", MySqlDbType.DateTime),
					new MySqlParameter("@baoliu1", MySqlDbType.VarChar,45),
					new MySqlParameter("@baoliu2", MySqlDbType.VarChar,45)};
			parameters[0].Value = model.baocun_id;
			parameters[1].Value = model.user_id;
			parameters[2].Value = model.zuihoutime;
			parameters[3].Value = model.dt_xuanze;
			parameters[4].Value = model.dt_jisuan;
			parameters[5].Value = model.dt_panduan;
			parameters[6].Value = model.dt_anli;
			parameters[7].Value = model.dt_caozuo;
			parameters[8].Value = model.mk_id;
			parameters[9].Value = model.k_id;
			parameters[10].Value = model.shengyutime;
			parameters[11].Value = model.baoliu1;
			parameters[12].Value = model.baoliu2;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(XinKuaiJi.Model.zaixianmokao model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update zaixianmokao set ");
			strSql.Append("user_id=@user_id,");
			strSql.Append("zuihoutime=@zuihoutime,");
			strSql.Append("dt_xuanze=@dt_xuanze,");
			strSql.Append("dt_jisuan=@dt_jisuan,");
			strSql.Append("dt_panduan=@dt_panduan,");
			strSql.Append("dt_anli=@dt_anli,");
			strSql.Append("dt_caozuo=@dt_caozuo,");
			strSql.Append("mk_id=@mk_id,");
			strSql.Append("k_id=@k_id,");
			strSql.Append("shengyutime=@shengyutime,");
			strSql.Append("baoliu1=@baoliu1,");
			strSql.Append("baoliu2=@baoliu2");
			strSql.Append(" where baocun_id=@baocun_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@user_id", MySqlDbType.Int32,11),
					new MySqlParameter("@zuihoutime", MySqlDbType.DateTime),
					new MySqlParameter("@dt_xuanze", MySqlDbType.VarChar,500),
					new MySqlParameter("@dt_jisuan", MySqlDbType.VarChar,45),
					new MySqlParameter("@dt_panduan", MySqlDbType.VarChar,45),
					new MySqlParameter("@dt_anli", MySqlDbType.VarChar,45),
					new MySqlParameter("@dt_caozuo", MySqlDbType.VarChar,45),
					new MySqlParameter("@mk_id", MySqlDbType.VarChar,45),
					new MySqlParameter("@k_id", MySqlDbType.Int32,11),
					new MySqlParameter("@shengyutime", MySqlDbType.DateTime),
					new MySqlParameter("@baoliu1", MySqlDbType.VarChar,45),
					new MySqlParameter("@baoliu2", MySqlDbType.VarChar,45),
					new MySqlParameter("@baocun_id", MySqlDbType.Int64,20)};
			parameters[0].Value = model.user_id;
			parameters[1].Value = model.zuihoutime;
			parameters[2].Value = model.dt_xuanze;
			parameters[3].Value = model.dt_jisuan;
			parameters[4].Value = model.dt_panduan;
			parameters[5].Value = model.dt_anli;
			parameters[6].Value = model.dt_caozuo;
			parameters[7].Value = model.mk_id;
			parameters[8].Value = model.k_id;
			parameters[9].Value = model.shengyutime;
			parameters[10].Value = model.baoliu1;
			parameters[11].Value = model.baoliu2;
			parameters[12].Value = model.baocun_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long baocun_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from zaixianmokao ");
			strSql.Append(" where baocun_id=@baocun_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@baocun_id", MySqlDbType.Int64,20)			};
			parameters[0].Value = baocun_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string baocun_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from zaixianmokao ");
			strSql.Append(" where baocun_id in ("+baocun_idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XinKuaiJi.Model.zaixianmokao GetModel(long baocun_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select baocun_id,user_id,zuihoutime,dt_xuanze,dt_jisuan,dt_panduan,dt_anli,dt_caozuo,mk_id,k_id,shengyutime,baoliu1,baoliu2 from zaixianmokao ");
			strSql.Append(" where baocun_id=@baocun_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@baocun_id", MySqlDbType.Int64,20)			};
			parameters[0].Value = baocun_id;

			XinKuaiJi.Model.zaixianmokao model=new XinKuaiJi.Model.zaixianmokao();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XinKuaiJi.Model.zaixianmokao DataRowToModel(DataRow row)
		{
			XinKuaiJi.Model.zaixianmokao model=new XinKuaiJi.Model.zaixianmokao();
			if (row != null)
			{
				if(row["baocun_id"]!=null && row["baocun_id"].ToString()!="")
				{
					model.baocun_id=long.Parse(row["baocun_id"].ToString());
				}
				if(row["user_id"]!=null && row["user_id"].ToString()!="")
				{
					model.user_id=int.Parse(row["user_id"].ToString());
				}
				if(row["zuihoutime"]!=null && row["zuihoutime"].ToString()!="")
				{
					model.zuihoutime=DateTime.Parse(row["zuihoutime"].ToString());
				}
				if(row["dt_xuanze"]!=null)
				{
					model.dt_xuanze=row["dt_xuanze"].ToString();
				}
				if(row["dt_jisuan"]!=null)
				{
					model.dt_jisuan=row["dt_jisuan"].ToString();
				}
				if(row["dt_panduan"]!=null)
				{
					model.dt_panduan=row["dt_panduan"].ToString();
				}
				if(row["dt_anli"]!=null)
				{
					model.dt_anli=row["dt_anli"].ToString();
				}
				if(row["dt_caozuo"]!=null)
				{
					model.dt_caozuo=row["dt_caozuo"].ToString();
				}
				if(row["mk_id"]!=null)
				{
					model.mk_id=row["mk_id"].ToString();
				}
				if(row["k_id"]!=null && row["k_id"].ToString()!="")
				{
					model.k_id=int.Parse(row["k_id"].ToString());
				}
				if(row["shengyutime"]!=null && row["shengyutime"].ToString()!="")
				{
					model.shengyutime=DateTime.Parse(row["shengyutime"].ToString());
				}
				if(row["baoliu1"]!=null)
				{
					model.baoliu1=row["baoliu1"].ToString();
				}
				if(row["baoliu2"]!=null)
				{
					model.baoliu2=row["baoliu2"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select baocun_id,user_id,zuihoutime,dt_xuanze,dt_jisuan,dt_panduan,dt_anli,dt_caozuo,mk_id,k_id,shengyutime,baoliu1,baoliu2 ");
			strSql.Append(" FROM zaixianmokao ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM zaixianmokao ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.baocun_id desc");
			}
			strSql.Append(")AS Row, T.*  from zaixianmokao T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "zaixianmokao";
			parameters[1].Value = "baocun_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

